package com.datastructure.test.recall.childrensets;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

/**
 * 返回集合的所有子集合
 */
public class ChildrenSets {
    static ArrayList<ArrayList<Integer>> res = new ArrayList<>();
    public static void main(String[] args) {
        int sum = 0;
        String data = "";
        Scanner scanner = new Scanner(System.in);
        if(scanner.hasNext()){
            int i = scanner.nextInt();
        }
        scanner.nextLine();
        if(scanner.hasNext()){
            data = scanner.nextLine();
        }
    }

    public static ArrayList<ArrayList<Integer>> subsets(int[] nums) {
        Arrays.sort(nums);
        LinkedList<Integer> track = new LinkedList<>();
        back(nums, 0, track);
        return res;
    }

    public static void back(int[] S, int start, LinkedList<Integer> track){
        res.add(new ArrayList<>(track));
        for(int i = start; i < S.length; i++){
            track.add(S[i]);
            back(S, i+1, track);
            //撤销 回溯
            track.removeLast();
        }
    }
}
